package club.janna.jrpc.rpc.protocol.jrpc;

import club.janna.jrpc.remoting.Codec;
import club.janna.jrpc.serialize.Serialization;

public class JRPCCodec implements Codec {

    private Serialization serialization;
    private Class<?> decodeType;

    public JRPCCodec(Serialization serialization, Class<?> decodeType) {
        this.serialization = serialization;
        this.decodeType = decodeType;
    }

    @Override
    public byte[] encode(Object obj) {
        return serialization.serialize(obj);
    }

    @Override
    public Object decode(byte[] bytes) {
        return serialization.deserialize(bytes, decodeType);
    }
}
